package servlet;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/image")
public class ImageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public ImageServlet() {
        super();
    }
	protected void doGet(HttpServletRequest request, 
			HttpServletResponse response) throws ServletException, IOException {
		BufferedImage image=new BufferedImage(400,400,BufferedImage.TYPE_INT_RGB);
		Graphics g=image.getGraphics();
		g.setColor(Color.GRAY);
		g.fillRect(0, 0, 400, 400);
		g.setColor(Color.RED);
		g.fillRect(0, 0, 100, 100);
		g.setColor(Color.GREEN);
		g.fillOval(200, 200, 50, 50);
		g.setColor(Color.BLUE);
		g.fillArc(300, 300, 100, 100, 0, 270);
		g.setFont(new Font("Arial",Font.BOLD,15));
		g.drawString("This image is generated by ImageServlet", 20, 300);
		ImageIO.write(image, "jpg", response.getOutputStream());	
	}
}
